package com.zhanhong.opencvdemo.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.zhanhong.opencvdemo.R;

import uk.co.senab.photoview.PhotoView;

public class PhotoActivity extends AppCompatActivity {

    public static void startAction(Context context, int index) {
        Intent intent = new Intent(context, PhotoActivity.class);
        intent.putExtra("index", index);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        initView();
    }

    private void initView() {
        int index = getIntent().getIntExtra("index", -1);
        if (index == -1 || MainActivity.mBitmaps.size() <= index) {
            finish();
            return;
        }
        findViewById(R.id.tv_exit).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        PhotoView pvPhoto = findViewById(R.id.pv_photo);
        pvPhoto.setImageBitmap(MainActivity.mBitmaps.get(index));
        TextView tvTitle = findViewById(R.id.tv_title);
        tvTitle.setText(MainActivity.mTitles.get(index));
    }
}
